 package sza.oracle.apps.ap.oie.webui;

import java.sql.CallableStatement;
import java.sql.Types;

import oracle.apps.ap.oie.webui.CashAndOtherCO;
 import oracle.apps.ap.oie.webui.NavigationUtility;
 import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.OAWebBeanFactory;
import oracle.apps.fnd.framework.webui.beans.OATipBean;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.layout.OADefaultSingleColumnBean;
import oracle.apps.fnd.framework.webui.beans.layout.OAHeaderBean;
import oracle.apps.fnd.framework.webui.beans.layout.OAMessageComponentLayoutBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;
import oracle.apps.fnd.framework.webui.beans.table.OATableBean;

import oracle.jbo.Row;
import oracle.jbo.server.DBTransaction;

import sza.oracle.apps.ap.oie.utility.SzaOIEUtil;
 
 public class SzaCashAndOtherCO extends CashAndOtherCO
 {
   public static final String RCS_ID = "$Header$";
   public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header$", "%packagename%");
 
   public void processRequest(OAPageContext pageContext, OAWebBean webBean)
   {
     String LogMessage = "";
     String LogFunction = "";
     LogFunction = "SZA SzaCashAndOtherCO.processRequest";
 
     LogMessage = "SZA SzaCashAndOtherCO.processRequest - Start";
 
     SzaOIEUtil.cmlinLog(pageContext, LogFunction, LogMessage);
 
     super.processRequest(pageContext, webBean);
       OAApplicationModule oaapplicationmodule = pageContext.getRootApplicationModule(); 
       OAViewObject HeaderVo = (OAViewObject)oaapplicationmodule.findViewObject("ExpenseReportHeadersVO");
       String expenseReportid = HeaderVo.first().getAttribute("ExpenseReportId")+"";
     
//        String returnValue = isTravleTemplate(expenseReportid,oaapplicationmodule);
//        if("TRA".equals(returnValue)){
//            OATipBean tip1 = (OATipBean)webBean.findIndexedChildRecursive("CreditLabel");
//            OATipBean tip2 = (OATipBean)webBean.findIndexedChildRecursive("CashLabel");
//            tip1.setRendered(Boolean.FALSE);
//            tip2.setRendered(Boolean.FALSE);
//        }   
     LogMessage = "SZA SzaCashAndOtherCO.processRequest - End";
 
     SzaOIEUtil.cmlinLog(pageContext, LogFunction, LogMessage);
//     throw new OAException(returnValue);
   }
 
   public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
   {
     String LogMessage = "";
     String LogFunction = "";
     LogFunction = "SZA SzaCashAndOtherCO.processFormRequest";
       
     LogMessage = "SZA SzaCashAndOtherCO.processFormRequest - Start";
    
     SzaOIEUtil.cmlinLog(pageContext, LogFunction, LogMessage);
   
     int CurrentPageIndex = NavigationUtility.getCurrentPageIndex(pageContext);
     LogMessage = "SZA SzaCashAndOtherCO.processFormRequest - CurrentPageIndex:" + CurrentPageIndex;
        
     SzaOIEUtil.cmlinLog(pageContext, LogFunction, LogMessage);
                 
     super.processFormRequest(pageContext, webBean);

     LogMessage = "SZA SzaCashAndOtherCO.processFormRequest - End";

     SzaOIEUtil.cmlinLog(pageContext, LogFunction, LogMessage);
      }
      
     /*
      * 判断是否是差旅费模版
      * */
      private String isTravleTemplate(String TemplateId, OAApplicationModule am) {
          String returnValue = "";
          String callStmt = 
              " begin SZA_OIE_BUDGET_UTIL.GET_REPORT_TEMPLATE_TYPE(p_expense_report_id => :1,\n" + 
              "                          o_return_value       => :2); end;";
          DBTransaction txn = am.getOADBTransaction();
          CallableStatement cs = null;
          Row row = null;
        
              try {
                  cs = txn.createCallableStatement(callStmt, 1);
                  cs.setString(1, TemplateId);
                  cs.setString(2, returnValue);
                  cs.registerOutParameter(2, Types.VARCHAR);
                  cs.execute();
                  returnValue = cs.getString(2);
                 
                  cs.close();
              } catch (Exception e) {
                  e.printStackTrace();
                  try {
                      cs.close();
                  } catch (Exception ex) {

                  }
              }
              return returnValue;

        
      }
 }



